package com.example.tellwin.mine.presenter;

import com.example.tellwin.AppHelper;
import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.mine.bean.UserBean;
import com.example.tellwin.mine.bean.UserContentBean;
import com.example.tellwin.mine.bean.UserInfo;
import com.example.tellwin.mine.contract.MineContract;
import com.example.tellwin.utils.HttpUtils;
import com.example.tellwin.utils.ToastUtil;

import javax.inject.Inject;

import okhttp3.RequestBody;

/**
 * @author : LinZePeng
 * @date : 2020/12/1
 * @Describe ：
 **/
public class MinePresenter extends RxPresenter<MineContract.View> implements MineContract.Presenter<MineContract.View> {

    private TwjfApi mApi;

    @Inject
    public MinePresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }


    @Override
    public void getUserInfo(int type) {
        mApi.getUserInfo(new SimpleCallback<UserContentBean>(mView) {
            @Override
            public void onSuccess(UserContentBean userContentBean) {
                if(userContentBean==null ||userContentBean.getUserInfo()==null){
                    ToastUtil.show(MainApplication.getCurActivity() , R.string.none_data);
                }
                AppHelper.getInstance().setUserInfo(userContentBean.getUserInfo());
                mView.userInfoResult(userContentBean ,type);
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void switchIdentity(int type) {
        RequestBody requestBody = HttpUtils.getRequestBody("type" , type +"");
        mApi.switchIdentity(requestBody , new SimpleCallback<UserBean>(mView) {
            @Override
            public void onSuccess(UserBean userBean) {
               // AppHelper.getInstance().setAnswerUserBean(userBean);
                mView.switchIdentity();
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }
}
